package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ProjectManagementFileDao;
import cn.topevery.garden.entity.po.ProjectManagementFile;
import cn.topevery.garden.entity.query.ProjectManagementFileQuery;
import cn.topevery.garden.entity.vo.ProjectManagementFileVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目管理 附件表
 *
 * @author code-generate
 * @date 2022-02-16
 */
@Service
public class ProjectManagementFileLogic extends BaseLogic<ProjectManagementFile> {
    @Autowired
    ProjectManagementFileDao projectManagementFileDao;

    @Override
    public BaseEntityDao<ProjectManagementFile, Integer> getDao() {
        return projectManagementFileDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<ProjectManagementFileVO> listPage(ProjectManagementFileQuery query) {
        return projectManagementFileDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        projectManagementFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param projectManagementFile 实体
     */
    public void saveOrUpdate(String userId, ProjectManagementFile projectManagementFile){
        projectManagementFileDao.saveOrUpdate(userId,projectManagementFile);
    }

    /**
         * 根据自定义列值来获取对象
         */
    public ProjectManagementFile getEntityByColumn(String key, String value) {
        return projectManagementFileDao.getEntityByColumn(key, value);
    }

    public List<ProjectManagementFile> getListByPid(Integer pId) {
        return projectManagementFileDao.getListByPid(pId);
    }

    public void saveOrUpdate(String userId, Integer pId, List<ProjectManagementFile> fileList) {
        projectManagementFileDao.deleteById(pId);
        for (ProjectManagementFile projectManagementFile : fileList) {
            projectManagementFile.setMainId(pId);
            projectManagementFileDao.saveOrUpdate(userId, projectManagementFile);
        }
    }

    public void deleteByMainId(Integer[] ids) {
        projectManagementFileDao.deleteByMainIds(ids);
    }
}
